﻿using DevExpress.DataAccess.Native.Json;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.下单MTO.Service;
using DXApplicationTangche.UC.全部工序.service;
using DXApplicationTangche.UC.生产计划.生产批生产.model;
using DXApplicationTangche.UC.生产计划.编排生产批.service;
using DXApplicationTangche.UC.订单一览新.辅料.service;
using Kingdee.BOS.WebApi.Client;
using mendian;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static DXApplicationTangche.UC.金蝶.dto.StockOutDTO;
using Newtonsoft.Json.Linq;


namespace DXApplicationTangche.UC.生产计划.生产批生产.service
{
    public class 生产批生产Service
    {
        public List<DTO辅料显示> dTO辅料显示s = new List<DTO辅料显示>();
        public List<StyleAccessoryDTO> styleAccessoryDTOs = new List<StyleAccessoryDTO>();
        public static List<DTO店铺> get店铺一览()
        {
            return
                FunctionHelper.JsonDeserialization<List<DTO店铺>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/pmc/getStores"
                    )
                );
        }
        /// <summary>
        /// 查询running状态批次
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static List<DTO生产批生产> get已排产一览(String code)
        {
            return
                FunctionHelper.JsonDeserialization<List<DTO生产批生产>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/pmc/findRunningWIPBatch?code=" + code
                    )
                );
        }
        public static List<DTO生产批> get已开立一览(String shopId)
        {
            return
                FunctionHelper.JsonDeserialization<List<DTO生产批>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/pmc/findWaitWIPBatchByShopId?shopId=" + shopId
                    )
                );
        }
        /// <summary>
        /// 仅裁剪工序使用无成果物提交
        /// </summary>
        /// <param name="mnemonic"></param>
        /// <param name="batchNo"></param>
        /// <param name="code"></param>
        public static void post扫码(String mnemonic, String batchNo, String code)
        {
            RestCall.PostHttp(
                    URL.接口url + "/project/saveBatchProjectInstance?mnemonic=" + mnemonic + "&batchNo=" + batchNo + "&code=" + code,
                    FunctionHelper.JsonSerialization(code)
                );
        }
        /// <summary>
        /// 工序扫码提交工序成果物
        /// </summary>
        /// <param name="mnemonic"></param>
        /// <param name="batchNo"></param>
        /// <param name="code"></param>
        /// <param name="projectAchievementDTO"></param>
        public static void post工序扫码(String mnemonic, String batchNo, String code, ProjectAchievementDTO projectAchievementDTO)
        {
            RestCall.PostHttp(
                    URL.接口url + "/project/saveBatchProjectInstance?mnemonic=" + mnemonic + "&batchNo=" + batchNo + "&code=" + code,
                    FunctionHelper.JsonSerialization(projectAchievementDTO)
                );
        }
        /// <summary>
        /// 初始化成衣在制品生产批
        /// </summary>
        /// <param name="mnemonic"></param>
        /// <param name="batchNo"></param>
        /// <param name="code"></param>
        /// <param name="projectAchievementDTO"></param>
        public static PlainMessageResult initBarcodeWipInstance(String barcode, String responsor)
        {
            return
                FunctionHelper.JsonDeserialization<PlainMessageResult>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/project/initBarcodeWipInstance?barcode=" + barcode + "&responsor=" + responsor
                    )
                );
        }
        /// <summary>
        /// 生产扫码
        /// </summary>
        /// <param name="mnemonic"></param>
        /// <param name="batchNo"></param>
        /// <param name="code"></param>
        /// <param name="projectAchievementDTO"></param>
        public static PlainMessageResult wipBarcodeScan(String barcode, String stepName, String responsor)
        {
            return
                FunctionHelper.JsonDeserialization<PlainMessageResult>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/project/wipBarcodeScan?barcode=" + barcode + "&stepName=" + stepName + "&responsor=" + responsor
                    )
                );
        }
        /// <summary>
        /// 判断是否执行裁剪后接收工序
        /// </summary>
        /// <param name="batchNo"></param>
        /// <returns></returns>
        public static PlainMessageResult judgeReceiveAfterClippingByBatchNo(String batchNo)
        {
            return
                FunctionHelper.JsonDeserialization<PlainMessageResult>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/project/judgeReceiveAfterClippingByBatchNo?batchNo=" + batchNo
                    )
                );
        }
        /// <summary>
        /// 判断是否执行裁剪工序
        /// </summary>
        /// <param name="batchNo"></param>
        /// <returns></returns>
        public static PlainMessageResult judgeClippingByBatchNo(String batchNo)
        {
            return
                FunctionHelper.JsonDeserialization<PlainMessageResult>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/project/judgeClippingByBatchNo?batchNo=" + batchNo
                    )
                );
        }
        /// <summary>
        /// 查询入库前工序，判断是否能入库
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public static Boolean checkStockInWipRecord(String barcode)
        {
            return
                FunctionHelper.JsonDeserialization<Boolean>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/project/checkStockInWipRecord?barcode=" + barcode
                    )
                );
        }
        /// <summary>
        /// 工序顺序提醒
        /// </summary>
        /// <param name="batchNo"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static PlainMessageResult validateProjectInstance(String batchNo, String code)
        {
            return
                FunctionHelper.JsonDeserialization<PlainMessageResult>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/project/validateProjectInstance?batchNo=" + batchNo + "&code=" + code
                    )
                );
        }
        /// <summary>
        /// 查询plan状态批次
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static List<DTO生产批生产> get已投产一览(String code)
        {
            return
                FunctionHelper.JsonDeserialization<List<DTO生产批生产>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/pmc/findPlanWIPBatch?code=" + code
                    )
                );
        }

        public static List<DTO.OrderShippedDTO> get已完成一览(String pageStart, String pageSize)
        {
            return
                FunctionHelper.JsonDeserialization<List<DTO.OrderShippedDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/pmc/getOrderShippedDaos?pageStart=" + pageStart + "&pageSize=" + pageSize
                    )
                );
        }

        public static String get查找设备session对应的员工(String assertNo)
        {
            String empNo;
            try
            {
                empNo = RestCall.httpGetMethod(URL.接口url + "/session/getEmpNoByAssertNo?assertNo=" + assertNo);
                if ("no content".Equals(empNo))
                {
                    return String.Empty;
                }
                else
                {
                    return empNo;
                }
            }
            catch
            {
                return String.Empty;
            }
        }

        public static void save保存设备session(String assertNo, String empNo)
        {
            RestCall.httpGetMethod(
                URL.接口url + "/session/saveFacilitySession?assertNo=" + assertNo + "&empNo=" + empNo);
        }
        /// <summary>
        /// 根据批号和工序查询辅料
        /// </summary>
        /// <param name="pageStart"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public 生产批生产Service(String batchNo, String wbsCode)
        {
            try
            {
                this.styleAccessoryDTOs =
                    FunctionHelper.JsonDeserialization<List<StyleAccessoryDTO>>(
                        RestCall.httpGetMethod(
                            URL.接口url + "/pmc/getStyleAccessoryByBarcodeAndWBSCode?barcode=" + batchNo + "&wbsCode=" + wbsCode
                        )
                    );
                foreach (StyleAccessoryDTO item in this.styleAccessoryDTOs)
                {
                    this.dTO辅料显示s.Add(new DTO辅料显示(item));
                }
            }
            catch { }
        }
        /// <summary>
        /// 样品订单查看成衣水洗标码
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public static String saleInitWIPBatchAndWarterMarkPrintLog(String orderId)
        {
            return
                RestCall.httpGetMethod(
                    URL.接口url + "/pmc/saleInitWIPBatchAndWarterMarkPrintLog?orderId=" + orderId
                );
        }
    }
    /// <summary>
    /// 生产工序
    /// </summary>
    public class BarcodeWipInstanceConsts
    {
        public const String PRODUCTION_START = "生产开始";
        public const String PIN_LOCK = "钉锁";
        public const String HALF_PRODUCT_INSPECTION = "半成品检查";
        public const String FIRST_PRODUCT_INSPECTION = "成品一检";
        public const String HAND_SEWING = "手缝";
        public const String FINISHED_PRODUCT_INSPECTION = "成品检查";
        public const String IRONING = "整烫";
    }
    public class DTO店铺
    {
        public String id { get; set; }//店铺id
        public String name { get; set; }//店铺name
        public DTO店铺()
        {

        }
    }
    public class DTO生产批生产
    {
        public String addressCity { get; set; }
        public String addressDetail { get; set; }
        public String addressDistrict { get; set; }
        public String addressId { get; set; }
        public String addressProvince { get; set; }
        public DateTime batchDate { get; set; }
        public String batchNo { get; set; }
        public Double batchQuantiry { get; set; }
        public String batchStatus { get; set; }
        public String composition { get; set; }
        public String customerCountId { get; set; }
        public String customerId { get; set; }
        public String customerName { get; set; }
        public String materialCode { get; set; }
        public String materialNameCn { get; set; }
        public String mobile { get; set; }
        public DateTime orderDate { get; set; }
        public String orderId { get; set; }
        public String orderNo { get; set; }
        public String refOrderId { get; set; }
        public String refOrderNo { get; set; }
        public String refStyleId { get; set; }
        public String styleFabricId { get; set; }
        public String styleId { get; set; }
        public String styleNameCn { get; set; }
        public String styleSizeCd { get; set; }
        public Boolean urgentFlg { get; set; }
        public String zipCode { get; set; }
        public String styleName { get; set; } //款式类别
        public Boolean done { get; set; } //是否裁剪
        public DTO生产批生产()
        {

        }
    }

}
